package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.TravelGroup;
import com.ktgj.customer.domain.TravelProductDto;
import com.ktgj.customer.domain.dto.ProductListDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.TravelProduct;
import com.ktgj.customer.service.ITravelProductService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 旅游产品Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/products")
public class TravelProductController extends BaseController
{
    @Autowired
    private ITravelProductService travelProductService;

    /**
     * 查询旅游产品列表
     */
    //@PreAuthorize(hasPermi = "customer:product:list")
    @GetMapping("/list")
    public TableDataInfo list(TravelProductDto travelProductDto)
    {
        startPage();
        List<TravelProductDto> list = travelProductService.selectTravelProductList(travelProductDto);
        return getDataTable(list);
    }

    /**
     * 导出旅游产品列表
     */
    //@PreAuthorize(hasPermi = "customer:product:export")
    @Log(title = "旅游产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelProductDto travelProductDto) throws IOException
    {
        List<TravelProductDto> list = travelProductService.selectTravelProductList(travelProductDto);
        ExcelUtil<TravelProductDto> util = new ExcelUtil<TravelProductDto>(TravelProductDto.class);
        util.exportExcel(response, list, "旅游产品数据");
    }

    /**
     * 获取旅游产品详细信息
     */
    //@PreAuthorize(hasPermi = "customer:product:query")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return AjaxResult.success(travelProductService.selectTravelProductById(productId));
    }

    /**
     * 新增旅游产品
     */
    //@PreAuthorize(hasPermi = "customer:product:add")
    @Log(title = "旅游产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelProductDto travelProductDto)
    {
        return toAjax(travelProductService.insertTravelProduct(travelProductDto));
    }

    /**
     * 修改旅游产品
     */
    //@PreAuthorize(hasPermi = "customer:product:edit")
    @Log(title = "旅游产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelProductDto travelProductDto)
    {
        return toAjax(travelProductService.updateTravelProduct(travelProductDto));
    }

    /**
     * 删除旅游产品
     */
    //@PreAuthorize(hasPermi = "customer:product:remove")
    @Log(title = "旅游产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(travelProductService.deleteTravelProductByIds(productIds));
    }

    /**
     * 团产品列表
     * */
    @PostMapping("/productList")
    public TableDataInfo productList(@RequestBody ProductListDto productListDto){
        startPage();
        List<TravelGroup> travelProductList = travelProductService.productList(productListDto);
        return getDataTable(travelProductList);
    }
}
